package com.mjh.zhujianju.service.set.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.livew.framework.base.service.impl.BaseServiceImpl;
import com.livew.framework.utils.XTListUtils;
import com.mjh.zhujianju.dao.set.PermissionUserMapper;
import com.mjh.zhujianju.model.set.PermissionEO;
import com.mjh.zhujianju.model.set.PermissionUserEO;
import com.mjh.zhujianju.service.set.PermissionUserService;
//import com.mysql.fabric.xmlrpc.base.Array;

@Service
public class PermissionUserServiceImpl extends BaseServiceImpl<PermissionUserEO> implements PermissionUserService{

	@Resource
	private PermissionUserMapper permissionUserMapper;
	
	public PermissionUserServiceImpl(PermissionUserMapper permissionUserMapper) {
		super(permissionUserMapper);
	}

	@Override
	public List<Long> getPermissionByUserId(Long userId) {
		if(userId==null) {
			return null;
		}
		PermissionUserEO user= new PermissionUserEO();
		user.setUserId(userId);
		List<PermissionUserEO> list = this.permissionUserMapper.selectListByCondition(user);
		if(XTListUtils.isEmpty(list)) {
			return null;
		}
		List<Long> permissionIds = new ArrayList<>();
		for (PermissionUserEO permissionUserEO : list) {
			permissionIds.add(permissionUserEO.getPermissionId());
		}
		return permissionIds;
	}

	@Override
	public void deleteByUserId(Long userId) {
		if(userId==null) {
			return;
		}
		permissionUserMapper.deleteByUserId(userId);
	}

	@Override
	public List<PermissionEO> findPermissionByUserId(Long userId) {
		List<PermissionEO>  list = 	permissionUserMapper.selectPermissionByUserId(userId);
		return list;
	}

	

}
